package hipro;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;

public class Services {
	public String call(String url, String soapAction, SoapObject soapObject){
		String res = "Error";

        //create soap serialize
        SoapSerializationEnvelope envelope = 
        	new SoapSerializationEnvelope(SoapEnvelope.VER11);
        //add soap Object for serialize
        envelope.setOutputSoapObject(soapObject);

        //instance and call web service
        HttpTransportSE aht = new HttpTransportSE(url);
        try {
        	System.out.println("URL : "+ url);
        	System.out.println("Action : "+soapAction.toString());
        	System.out.println("Number of params: " +soapObject.getPropertyCount());
        	for(int i = 0; i< soapObject.getPropertyCount(); i++){
        		System.out.println("Parms :"+ soapObject.getProperty(i).toString());
        	}
        	
            aht.call(soapAction, envelope);
            System.out.println("Enter here");
            SoapObject result = (SoapObject) envelope.bodyIn;
            res = result.getProperty("return").toString();
        } catch (Exception e) {
        	System.out.println(e.toString());
        	res = e.toString();
        }
		
		return res;
	}
}
